<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$no		= $HTTP_GET_VARS['no'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Nm_Keluarga) as No, Nm_Keluarga, Hubungan, JKel, TempatLahir, TingkatPendidikan, Pekerjaan, Alamat, IsTertanggung, CONVERT(CHAR(21), Tgl_Lahir, 103) tgl_lahir FROM Keluarga A, MstData B, VPendidikan C WHERE NIK='$nik' AND B.GroupCode='hubungankeluarga' AND B.Code=A.Hubungan AND A.TingkatPendidikan=C.kode) SELECT * FROM limit WHERE No='$no'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}

		if(document.FEmployee.nama_keluarga.value == "")
		{
			alert("Field : Nama Keluarga tidak boleh kosong ...");
			document.FEmployee.nama_keluarga.focus();
			return false;
		}
		
		if(document.FEmployee.hubungan.value == "")
		{
			alert("Field : Hubungan tidak boleh kosong ...");
			document.FEmployee.hubungan.focus();
			return false;
		}

		if(document.FEmployee.gender.value == "")
		{
			alert("Field : Gender tidak boleh kosong ...");
			document.FEmployee.gender.focus();
			return false;
		}
/*
		if(document.FEmployee.tempat_lahir.value == "")
		{
			alert("Field : Tempat Lahir tidak boleh kosong ...");
			document.FEmployee.tempat_lahir.focus();
			return false;
		}

		if(document.FEmployee.tgl_lahir.value == "")
		{
			alert("Field : Tanggal Lahir tidak boleh kosong ...");
			document.FEmployee.tgl_lahir.focus();
			return false;
		}
*/
		if(document.FEmployee.pendidikan.value == "")
		{
			alert("Field : Pendidikan tidak boleh kosong ...");
			document.FEmployee.pendidikan.focus();
			return false;
		}
/*
		if(document.FEmployee.pekerjaan.value == "")
		{
			alert("Field : Pekerjaan tidak boleh kosong ...");
			document.FEmployee.pekerjaan.focus();
			return false;
		}

		if(document.FEmployee.alamat.value == "")
		{
			alert("Field : Alamat tidak boleh kosong ...");
			document.FEmployee.alamat.focus();
			return false;
		}
*/
		if(document.FEmployee.tertanggung.value == "")
		{
			alert("Field : Tertanggung tidak boleh kosong ...");
			document.FEmployee.tertanggung.focus();
			return false;
		}

		document.FEmployee.submit();
		
	}
</script>
</head>
<form name="FEmployee" method="post" action="<?=$Faction?>" >
<table width="100%">
 <tr>
  <td colspan="2"></td>
<table width="100%">
 <tr>
  <td colspan="2">
	<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;<b>Data Keluarga</b></td>
	</tr>
	<tr>
	 <tr>
	  <td>&nbsp;</td>
	 <td align="right">
	 <a href="../lib/detailemp.php?show=pribadi&amp;nik=<?=$nik?>">Data Pribadi</a> &raquo; 
	 <a href="../lib/detailemp.php?show=data_umum&amp;nik=<?=$nik?>">Data Umum</a> &raquo; 
	 <a href="../lib/detailemp.php?show=pendidikan&amp;nik=<?=$nik?>">Pendidikan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=kecakapan&amp;nik=<?=$nik?>">Kecakapan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=keluarga&amp;nik=<?=$nik?>"><b>Keluarga</b></a> &raquo; 
	 <a href="../lib/detailemp.php?show=karir&amp;nik=<?=$nik?>">Pengalaman</a> &raquo; 
	 <a href="../lib/detailemp.php?show=organisasi&amp;nik=<?=$nik?>">Organisasi</a> 
	 </td>
	 </tr>
	</table>
  </td>
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
 </tr>
 <tr>
 <td>
 <table >
 <tr>
  <td><b>NIK</b></td>
  <td>: <input type="text" maxlength="10" readonly="" value="<?=$nik?>" style="font-weight:bold;" class="text" name="nik"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Nama Keluarga</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[Nm_Keluarga]?>" size="45"  class="text" name="nama_keluarga"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Hubungan</td>
  <td>: 
  <select name="hubungan">
   <?
   	$sqhub	= mssql_query("SELECT * FROM VHubKel Where kode='$row[Hubungan]'",$conn);
	$rqhub 	= mssql_fetch_array($sqhub);
	echo"<option value='$rqhub[kode]'>$rqhub[nama]</option>";
   ?>
   <option value="">-Pilih-</option>
   
   <?
   	$shub	= mssql_query("SELECT * FROM VHubKel Order By nama",$conn);
	while($rhub = mssql_fetch_array($shub)){
		echo"<option value='$rhub[kode]'>$rhub[nama]</option>";
	}
   ?>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Gender</td>
  <td>: 
   <select name="gender">
   <?
   	if($row[JKel] == "0"){
    	echo'<option value="0">Pria</option>';
	}
	elseif($row[JKel] == "1"){
		echo'<option value="1">Wanita</option>';
	}
   ?>
    <option value="">-Pilih-</option>
	<option value="0">Pria</option>
	<option value="1">Wanita</option>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Tempat Lahir</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[TempatLahir]?>" class="text" name="tempat_lahir"/></td>
 </tr>
 <tr>
  <td>Tanggal Lahir</td>
  <td>: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[tgl_lahir]?>" name="tgl_lahir"/>
  <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  <!--<span class="InfoForm">Format: dd/mm/yyyy</span>-->
  </td>
 </tr>
 <tr>
  <td>Pendidikan</td>
  <td>: 
   <select name="pendidikan">
   <?
   	$dp = mssql_query("SELECT * FROM VPendidikan Where kode='$row[TingkatPendidikan]'",$conn);
	$rp = mssql_fetch_array($dp);
	echo"<option value='$rp[kode]'>$rp[nama]</option>";
   ?>
    <option value="">-Pilih-</option>
		<?
			$Pnd = mssql_query("SELECT * FROM VPendidikan",$conn);
			while($Rnd = mssql_fetch_array($Pnd)){
				echo"<option value='$Rnd[kode]'>$Rnd[nama]</option>";
			}
		?>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Pekerjaan</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[Pekerjaan]?>"  class="text" name="pekerjaan"/></td>
 </tr>
 <tr valign="top">
  <td valign="top">Alamat</td>
  <td valign="top">&nbsp; <textarea rows="4" cols="33" wrap="virtual" name="alamat"><?=$row[Alamat]?></textarea>
  </td>
 </tr>
 <tr>
  <td>Tertanggung</td>
  <td>: 
  	<select name="tertanggung">
	<?
		if($row[IsTertanggung] == "1"){
			echo'<option value="1">Ya</option>';
		}
		elseif($row[IsTertanggung] == "0"){
			echo'<option value="0">Tidak</option>';
		}
	?>
	 	<option value="">-Pilih-</option>
		<option value="1">Ya</option>
		<option value="0">Tidak</option>
	</select>
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td align="left"><br /><br />
  <input type="hidden" name="cat" value="keluarga" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Batal" class="button" onclick="Javascript:history.back();"/><input type="button" value="<?=$Vbutton?>" class="button" onClick="Validate();" />
  <br /><br />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.tgl_lahir,"99/99/9999");

//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms['FEmployee'].elements['tgl_lahir']);
	calA.year_scroll = true;
	calA.time_comp = false;	
</script>

<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
